package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @version v1.0
 * @apiNote 购物车持久层
 * @author OldGj 2024/5/22
 */
@Mapper
public interface ShoppingCartMapper {


    /**
     * 根据条件查询商品是否存在购物车
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);


    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> listAll(Long userId);

    /**
     * 向购物车中插入数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name,number, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) VALUES " +
            "(#{name},#{number},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 更新商品数量
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteAll(Long userId);

    /**
     * 删除购物车中一个商品
     * @param shoppingCart
     */
    void updateSub(ShoppingCart shoppingCart);

    /**
     * 根据ID删除购物车数据
     * @param shoppingCart
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(ShoppingCart shoppingCart);

    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
